Skip to content

fix(sema): handle missing Type variants in is_fixed_reference_type#1884

Open
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
ArshLabs:fix/issue-1882-value-type-reference
Open

fix(sema): handle missing Type variants in is_fixed_reference_type#1884
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
ArshLabs:fix/issue-1882-value-type-reference

Conversation

@ArshLabs
Copy link
Copy Markdown

Fixes #1882

is_fixed_reference_type panics with unreachable! when it encounters Type::Value, which happens when msg.value is placed inside an array literal and subscripted (e.g. [msg.value][0] <= 0).

The array subscript path in subscript.rs calls array_ty.deref_memory().is_fixed_reference_type(ns) to decide whether to keep the array pointer or load the value. For an array whose element type is Type::Value, this call hits the catch-all unreachable! arm because Type::Value was not listed in the match.

Type::Value is a primitive integer type (is_primitive and is_integer both return true for it in the same file), so the correct return value is false -- it is not a fixed-size reference type.

This patch replaces the unreachable! catch-all with explicit arms for the five Type variants that were missing from the match: Value, Void, Unreachable, BufferPointer, and SorobanHandle. All return false since none of them are reference types. This also makes the match exhaustive, preventing similar panics if the Type enum gains new variants in the future.

Reproduce:

contract C {
    function f() public payable returns (bool) {
        return [msg.value][0] <= 0;
    }
}
solang compile --target polkadot mre.sol

Before: thread 'main' panicked at src/sema/types.rs:1427:18
After: compiles without error.

Signed-off-by: Arshdeep Singh <arshdeep.ssingh777@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler panic in sema: unreachable! in is_fixed_reference_type on Type::Value when comparing an array-literal subscript of msg.value

1 participant